﻿<?php
$save	= @(int)$_POST['save'];
if($this_cata_id==1&&$save	== 1){
    $tbl_main   = $_TABLES['app'];
    $type	= @(int)$_POST['type'];
    $aid	= @(int)$_POST['aid'];
    if($type==1){
        $urlnamedd='出价';
        $money = @(double)$_POST['money'];
        $where=' and money="'.$money.'"';
        $result['money']=$money;
    }else{
        $urlnamedd='购买';
        $where='';
    }
    $url    = "$G_web_root/projects/display.php?aid=$aid";
    $second = '3';
    $msg    = '<font style="color:red">操作失败！</font>';
    $user   = $_SESSION[$G_front_session_key];
    if (!($user['members_uid'])){ 
        $info='请先登录！';
        $tpl->assign(get_defined_vars());
        $tpl->display('showmessage.html');
    	exit();
    }
    $sql = "SELECT COUNT(*) AS rs_count FROM $tbl_main where uid={$user['members_uid']} and type=$type and aid=$aid $where";
    $rs = $conn->GetOne($sql);
    if($rs) {
        $info='你已提交过相同的内容!';
        $tpl->assign(get_defined_vars());
        $tpl->display('showmessage.html');
    	exit();
    }else{
        $result['uid']=$user['members_uid'];
        $result['aid']=$aid;
        $result['type']=$type;
        $result['add_time']=$timestamp;
        $conn->AutoExecute($tbl_main,$result,'INSERT');
        $id = $conn->Insert_ID();
        if($id){
            $info=$urlnamedd.'成功！';
            $url="$G_web_root/members/";
            $msg    = '操作成功';
            $urlnamedd='会员中心';
            $tpl->assign(get_defined_vars());
            $tpl->display('showmessage.html');
        	exit();
        }else{
            $info=$urlnamedd.'失败，请重试！';
            $tpl->assign(get_defined_vars());
            $tpl->display('showmessage.html');
        	exit();
        }
    }
}

//请求提交报告
$username=$_GET["username"];
if($username){
$aid=$_GET["aid"];
$title=$_GET["title"];
$second = '3';
 	$sql = "SELECT COUNT(*) AS rs_count FROM yu_sqbg where username='".$username."' and aid=".$aid;
    $rs = $conn->GetOne($sql);

    if($rs) {
		$url="$G_web_root/projects/display.php?aid=".$aid;	
        $info='你已提交过请求了!';
        $tpl->assign(get_defined_vars());
        $tpl->display('showmessage.html');
    	exit();
    }else{
		$result['aid']=$aid;
		$result['title']=$title;
		$result['username']=$username;
		$result['ctime']=time();
		
		$conn->AutoExecute("yu_sqbg",$result,'INSERT');
		$id = $conn->Insert_ID();
		
		$conn->Execute("update yu_article set sqcs=(sqcs+1) where aid=".$aid);
		$id = $conn->Insert_ID();
	
		$info='您的要求上传报告已提交！';
		$url="$G_web_root/projects/display.php?aid=".$aid;			
		$msg    = '要求提交成功！';
		$urlnamedd='鉴定报告';
		$tpl->assign(get_defined_vars());
		$tpl->display('showmessage.html');
		exit();
	}
}
//===============

$commonone='';

if(isset($_GET['aid']))
	$aid = @(int)$_GET['aid'];

$acontent   = & article_content($aid);

//print_r($acontent);
//exit;

$alst=articlelast($acontent['aid'],$acontent['cid'],$acontent['cata_id']);//相对页面的下一篇
$anext=articlenext($acontent['aid'],$acontent['cid'],$acontent['cata_id']);//相对页面的上一篇

$cid        = $acontent['cid'];
$thisclass  = & class_info($cid);


$acontent_img    = getimagesize($G_web_root . '/uploads/'.$acontent['small_image']);
$img_width  = $acontent_img[0];


//$location   = location($cid) .'<font class="red fontB">'.substr($acontent['article_title'],0,66).'</font>';   // 得到当前路径
$location   = location($cid);   // 得到当前路径
artseo($acontent, $thisclass);      // 初始化页面seo数据
$side       = class_list(array('cid' => $this_cata_id, 'title_length' => 40), 1);


// Zunz
// + ---处理分页符 开始-- +//
// + -------------------------------------- + //
// $G_cfg['article_cfg']['article_page_split'] 为编辑器中的分页符
    $content    =   $acontent['content'];
    $G_cfg['article_cfg']['article_page_split'] = "<div style=\"page-break-after: always\"><span style=\"display: none\">&nbsp;</span></div>";
    $arr_content = explode($G_cfg['article_cfg']['article_page_split'], $content);  // 按分页符把文章内容切成数组
    $page   = @(int)$_GET['p'];                  // GET传递页码page参数
    $pamount= sizeof($arr_content);                 // 所切数组的大小
    if($page <= 0) $page = 1;                       // 当$page不存在时，为首页
    if($page > $pamount && $pamount > 0) $page = $pamount;  // 当$page大于数组大小值时，为尾页
    $content = $arr_content[$page-1];               
    $strpage = '';
    if($pamount > 1) {
        for($i=0;$i<$pamount;$i++) {
            if($i+1 == $page) {
                $strpage .= '[<span style="color:red">' . ($i+1) . '</span>] | ';
            } else {
                $strpage .= '[<a href="display.php?aid=' . $aid . '&p=' . ($i+1) . '" title="' . $acontent['article_title'] . ' 第' . ($i+1) . '页" target="_self">' . ($i+1) . '</a>] | ';
            }
        }
        $strpage = substr($strpage, 0, strlen($strpage)-3);
    }

    $acontent['strpage']    = $strpage;             // 分页
    $acontent['content']    = $content;             // 当前页面的“内容”
// + -------------------------------------- + //
// + ---处理分页符 结束-- +//

$att    = explode('|', $acontent['att']);
$acontent['attr']='';
if(is_array($att)) {
    $icount = 0;
    foreach($att as $v) {
        $v  = trim($v);
        if($v == '') continue;

        $br = $icount > 0 ? '<br>' : '';
        $vfilename  = substr($v, (strrpos($v, '/')+1));
        $acontent['attr'].= "<a href=\"{$G_web_upload}{$v}\" target=\"_blank\">下载报告</a> <br>";
        $icount ++;
    }
}



// + --------相关链接处理------------------------ + //
// 相关链接
$artrel = array();
$arrkey = explode(',', $acontent['keywords']);
if(is_array($arrkey) && sizeof($arrkey) > 0) {
    $where  = 'WHERE display = 1 AND aid <> ' . $aid . ' AND cata_id = ' . $this_cata_id . ' ';
    $tmp    = '';
    foreach($arrkey as $key) {
        $key = trim($key);
        if($key != '') {
            $tmp .= "OR (article_title LIKE '%$key%' OR keywords LIKE '%$key%')";
        }
    }
    if($tmp != '') {
        $tmp = substr($tmp, 2);
        $tmp = "( {$tmp} )";
        $where .= ' AND ' . $tmp;
        $sql    = "SELECT * FROM {$_TABLES['article']} $where LIMIT 0,8";
         //echo $sql;
        $conn   = & get_db_conn();
        $rs     = & $conn->Execute($sql);
        $artrel = $rs->GetRows();
    }
    if(is_array($artrel) && sizeof($artrel) > 0) {
        $artrel = $artrel;
    } else {
        $sql    = "SELECT * FROM {$_TABLES['article']} WHERE display = 1 AND cid = '$cid' AND aid <> '$aid' LIMIT 0,8";
         //echo $sql;
        $conn   = & get_db_conn();
        $rs     = & $conn->Execute($sql);
        $artrel = $rs->GetRows();
    }
}
//print_r($artrel);
if($artrel) {
    $i_related  = 1;
    foreach($rs as $article) {
            $item   = array();
            $aid_related            = @(int)$article['aid'];
            $article_title_related  = stripslashes(htmlspecialchars($article['article_title']));
            $simple_title_related   = stripslashes(htmlspecialchars($article['simple_title']));
            $pub_time_related       = $article['pub_time'];
            
            // 文章分类相关
            $cata_id_related    = @(int)$article['cata_id'];
            $cinfo_related  = get_node_info($GLOBALS[$class_var], $cata_id_related);
            $modpath_related  = $cinfo_related['cata_dir'];
            if(!$modpath_related) {
                $modpath_related    = $this_cata_dir;
            }
            // 当前文章的url链接
            $url_related        = $article['url'];
            if($url_related != '') {
                $url_this_article_related   = $url_related;
            } else {
                $url_this_article_related   = $G_app_root . '/' . $modpath_related . '/' . $file_display .
                    $opt_pseudostatic_url_php .
                    $opt_pseudostatic_url_question .
                    'aid' .
                    $opt_pseudostatic_url_equal .
                    $aid .
                    $opt_pseudostatic_url_ext;
            }
            

            $item_related   = array(
                'aid'   => $aid_related,
                'cid'   => $cid_related,
                'cname' => $cname_related,
                'article_title' => $article_title_related,
                'simple_title'  => $simple_title_related,
                'pub_time'      => $pub_time_related,
                'ftimehis' => date('Y-m-d H:i:s', $pub_time_related),
                'ftimehi' => date('Y-m-d H:i', $pub_time_related),
                'ftime' => date(DATE_FORMAT, $pub_time_related),
                'ftimehis'  => date('Y-m-d H:i:s',$pub_time_related),
                'ftimehi'  => date('Y-m-d H:i',$pub_time_related),
                'ftimemd'   => date('m-d',$pub_time_related),
                'aurl'  => $url_this_article_related,
                'hits'  => $article['hits'],
                'icount'  => $i_related,
                'price'         => sprintf("%01.2f",round($article['price1'])),
                );

            // 文章缩略图
            $item_related['thumb_img']   = get_thumbimg_url($article['small_image'], $G_web_common . '/images/nopic.jpg');
            

            // 使用简题
            $stitle = 1;

            $item_related['atitle'] = $article_title_related;
            if($stitle == 1 && $item_related['simple_title'] != '') $item_related['atitle_cut'] = $item_related['simple_title'];
            else $item_related['atitle_cut'] =  utf8_substr($article_title_related, '40');

            $title_style = '';
            if($article['tcolor'] != '') $title_style .= 'color:' . $article['tcolor'] . ';';
            if($title_style != '') {
                $item_related['atitle_cut'] = '<font style="' . $title_style . '">'.$item_related['atitle_cut'].'</font>';
            }

            //$item['atitle_cut'] = utf8_substr($article_title, '20');

            $related[] = $item_related;

    $i_related++;
    }
}
// + -------------------------------------- + //
// Zunz
$ntime=time();
$uid=$user['members_uid'];
$tbl_collect   = "yu_ymb";
$sql         = "SELECT count(*) co FROM $tbl_collect WHERE uid='$uid' and etime > $ntime and ymtype=2";
$buybo    = $conn->GetRow($sql);
$buybo=$buybo['co'];//是否购买易买宝

$aid=$_GET['aid'];

//是查看过联系方式
$arr   = $conn->GetRow("select COUNT(*) as rscount from yu_ishow where aid={$aid} and uid={$user['members_uid']}");
$isint=$arr["rscount"];	

//查看联系方式
if($_GET["ishow"]==1 and $isint <= 0){
	$tbl_main   = "yu_xmyx";
	$tbl_collect= "yu_members";
	$tbl_account   = "yu_account_log";		
	$sql    = "SELECT balance FROM $tbl_collect WHERE uid='{$user['members_uid']}'";
	$hjj    = $conn->GetRow($sql);
	$hjj=$hjj['balance'];//当前拥有黄金券
	$hfee=5;//定义查看留言所需黄金券
	$shjj=$hjj-$hfee;
	$stime=time();

	if($shjj >= 0){
		$sql="update $tbl_collect set balance=$shjj where uid=".$user['members_uid'];
		if($conn->Execute($sql)){			
			$conn->Execute("insert into $tbl_account(userid,type,flow,balance,amount,object_type,object_id,change_date,remark,add_time) values({$user['members_uid']},0,1,$hfee,$hfee,1,$aid,now(),'查看项目联系方式',$stime)");//加入日志	
			$conn->Execute("insert into yu_ishow(uid,aid,display) values({$user['members_uid']},{$aid},1)");//改变状态
		echo "<script>location='display.php?aid=$aid#linkman';</script>";
		exit;			
		}else{
			echo "<script>alert('出现错误，请重试！');history.back();</script>";
			exit;
		}
	}else{
		echo "<script>alert('您黄金券余额不足，请充值黄金券！');location='gmcz.php';</script>";
		exit;
	}
}

$tpl->assign(array(
    'page_title'    => $page_title,
    'seo_title'     => $seo_title,
    'seo_keywords'  => $seo_keywords,
    'seo_description' => $seo_description,
    'alst'      => $alst,    
    'anext'      => $anext,
    'cid'       => $cid,
    'aid'       => $aid,
    'location'  => $location,
    'side'      => $side,
    'thisclass' => $thisclass,
    'acontent'  => $acontent,
    'related'   => $related,
    'artrel'    => $artrel,
	'thisclass'		=>$thisclass,
	'front'		=> $front,
	'behind'	=> $behind,
    'img_width' => $img_width,
    'commonone' => $commonone,
    'usertypeid' => $user["members_type"],
    'buybo' => $buybo,
    'isint' => $isint,
    ));

//print_r(getimglist($aid));
//exit;
$tpl->display($tpl_display);
?>
